import { regTestPhone } from '@/utils';
import mcApi from 'mc-c2b2m-operator-api';
import { BasicColumn, FormSchema } from '@/components/Table';

const { SystemModule } = mcApi;
const { PositionApi } = SystemModule;

export const tableColumns: BasicColumn[] = [
  { title: '账号', dataIndex: 'account' },
  { title: '姓名', dataIndex: 'realName' },
  { title: '昵称', dataIndex: 'nickName' },
  {
    title: '部门角色',
    dataIndex: 'departmentPositionList',
    slots: { customRender: 'departmentPosition' },
  },
  {
    title: '是否应用管理',
    dataIndex: 'isAppAdministrator',
    customRender: (text) => (text ? '是' : '否'),
  },
  { title: '创建时间', dataIndex: 'createdTime' },
  // { title: '更新时间', dataIndex: 'updatedTime' },
];

export const tableFormSchema: FormSchema[] = [
  {
    field: 'realName',
    label: '姓名',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'nickName',
    label: '昵称',
    component: 'Input',
    colProps: { span: 6 },
  },
];

export const modalFormSchema: FormSchema[] = [
  {
    label: '账号',
    required: true,
    field: 'account',
    component: 'Input',
    componentProps: {
      placeholder: '请输入11位手机账号',
    },
    rules: [
      {
        required: true,
        validator(_, value, callback) {
          if (!value) callback('账号必填');
          if (!regTestPhone(value)) callback('请输入正确的手机号码');
          callback();
        },
      },
    ],
  },
  {
    label: '姓名',
    required: true,
    field: 'realName',
    component: 'Input',
  },
  {
    label: '昵称',
    required: true,
    field: 'nickName',
    component: 'Input',
  },
];

export const positionFormSchema: FormSchema[] = [
  {
    ifShow: false,
    field: 'memberId',
    label: 'memberId',
    component: 'Input',
  },
  {
    required: true,
    field: 'orgPositionId',
    label: '角色',
    component: 'ApiSelect',
    componentProps: {
      api: PositionApi.getOrgPosition,
      labelField: 'name',
      valueField: 'id',
      resultField: 'items',
      params: {
        pageSize: 100,
        desc: 'op.created_time',
      },
    },
  },
];
